package org.nfyszny.zzzs.modules.controller;

import java.text.ParseException;
import java.util.Arrays;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoDict;
import org.jeecg.common.system.query.QueryGenerator;

import org.nfyszny.zzzs.modules.entity.ZzzsExamine;
import org.nfyszny.zzzs.modules.service.IZzzsExamineService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.nfyszny.zzzs.modules.vo.ExamineRecordVo;
import org.nfyszny.zzzs.modules.vo.TimeOutVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 审批表
 * @Author: jeecg-boot
 * @Date: 2022-11-14
 * @Version: V1.0
 */
@Api(tags = "审批表")
@RestController
@RequestMapping("/modules/zzzsExamine")
@Slf4j
 class ZzzsExamineController extends JeecgController<ZzzsExamine, IZzzsExamineService> {
    @Autowired
    private IZzzsExamineService zzzsExamineService;


    /**
     * 分页列表查询
     *
     * @param zzzsExamine
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "审批表-分页列表查询")
    @ApiOperation(value = "审批表-分页列表查询", notes = "审批表-分页列表查询")
    @GetMapping(value = "/list")
    @AutoDict
    public Result<IPage<ZzzsExamine>> queryPageList(ZzzsExamine zzzsExamine,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<ZzzsExamine> queryWrapper = QueryGenerator.initQueryWrapper(zzzsExamine, req.getParameterMap());
        Page<ZzzsExamine> page = new Page<ZzzsExamine>(pageNo, pageSize);
        IPage<ZzzsExamine> pageList = zzzsExamineService.page(page, queryWrapper);
        return Result.TOK(pageList);
    }

    /**
     * 按年度统计审核超时报表
     */
    @ApiOperation(value = "审批表-按年度统计审核超时报表", notes = "审批表-按年度统计审核超时报表")
    @GetMapping(value = "/getYearTimeoutInfo")
    @AutoLog(value = "审批表-按年度统计审核超时报表")
    public Result getYearTimeoutInfo(@RequestParam(value = "year", required = false) String year) throws ParseException {
        System.out.println("year = " + year);
        List<TimeOutVo> list = zzzsExamineService.getYearTimeoutInfo(year);
        return Result.TOK(list);
    }

    /**
     * 按年度统计审核超时报表
     */
    @ApiOperation(value = "审批表-按月份统计审核超时报表", notes = "审批表-按年度统计审核超时报表")
    @GetMapping(value = "/getMonthTimeoutInfo")
    @AutoLog(value = "审批表-按月份统计审核超时报表")
    public Result getMonthTimeoutInfo(@RequestParam(value = "year", required = false) String date) throws ParseException {

        List<TimeOutVo> list = zzzsExamineService.getMonthTimeoutInfo(date);
        return Result.TOK(list);
    }

    /**
     * 按季度统计审核超时报表
     */
    @ApiOperation(value = "审批表-按年度统计审核超时报表", notes = "审批表-按年度统计审核超时报表")
    @GetMapping(value = "/getQuarteTimeoutInfo")
    @AutoLog(value = "审批表-按年度统计审核超时报表")
    public Result getQuarteTimeoutInfo(@RequestParam(value = "quarte", required = false) String quarte) throws ParseException {
        System.out.println("quarte = " + quarte);
        List<TimeOutVo> list = zzzsExamineService.getQuarteTimeoutInfo(quarte);
        return Result.TOK(list);
    }

    /**
     * 审批
     *
     * @param zzzsExamine
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "审批表-分页列表查询", notes = "审批表-分页列表查询")
    @GetMapping(value = "/listRecorded")
    @AutoDict
    @AutoLog(value = "审批表-分页列表查询")
    public Result<IPage<ZzzsExamine>> Recorded(ZzzsExamine zzzsExamine,
                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                               HttpServletRequest req) {


        QueryWrapper<ZzzsExamine> queryWrapper = QueryGenerator.initQueryWrapper(zzzsExamine, req.getParameterMap());
        Page<ZzzsExamine> page = new Page<ZzzsExamine>(pageNo, pageSize);
        IPage<ZzzsExamine> pageList = zzzsExamineService.selectRecorded(queryWrapper, page);
        return Result.TOK(pageList);
    }


    @ApiOperation(value = "审批表-审批备案", notes = "审批表-审批备案")
    @PostMapping("/examineRecord")
    @AutoLog(value = "审批备案")
    public Result examineRecord(@RequestBody ExamineRecordVo recordVo) {
        zzzsExamineService.examineRecord(recordVo);
        return Result.TOK();

    }

    @ApiOperation(value = "审批表-examineList", notes = "审批表-分页列表查询")
    @GetMapping(value = "/examineList")
    @AutoDict
    @AutoLog(value = "审批表-分页列表查询")
    public Result<IPage<ZzzsExamine>> queryPageListByStatusEqCreateAndStatusEqTimeout(ZzzsExamine zzzsExamine,
                                                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                                      HttpServletRequest req) {
        QueryWrapper<ZzzsExamine> queryWrapper = QueryGenerator.initQueryWrapper(zzzsExamine, req.getParameterMap());
        Page<ZzzsExamine> page = new Page<ZzzsExamine>(pageNo, pageSize);

        IPage<ZzzsExamine> pageList = zzzsExamineService.selectExamineList(queryWrapper, page);
        return Result.TOK(pageList);
    }

    /**
     * 添加
     *
     * @param zzzsExamine
     * @return
     */
    @AutoLog(value = "审批表-添加")
    @ApiOperation(value = "审批表-添加", notes = "审批表-添加")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_examine:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody ZzzsExamine zzzsExamine) {
        zzzsExamineService.save(zzzsExamine);
        return Result.TOK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param zzzsExamine
     * @return
     */
    @AutoLog(value = "审批表-编辑")
    @ApiOperation(value = "审批表-编辑", notes = "审批表-编辑")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_examine:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody ZzzsExamine zzzsExamine) {
        zzzsExamineService.updateById(zzzsExamine);
        return Result.TOK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "审批表-通过id删除")
    @ApiOperation(value = "审批表-通过id删除", notes = "审批表-通过id删除")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_examine:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        zzzsExamineService.removeById(id);
        return Result.TOK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "审批表-批量删除")
    @ApiOperation(value = "审批表-批量删除", notes = "审批表-批量删除")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_examine:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.zzzsExamineService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.TOK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "审批表-通过id查询")
    @ApiOperation(value = "审批表-通过id查询", notes = "审批表-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ZzzsExamine> queryById(@RequestParam(name = "id", required = true) String id) {
        ZzzsExamine zzzsExamine = zzzsExamineService.getById(id);
        if (zzzsExamine == null) {
            return Result.error("未找到对应数据");
        }
        return Result.TOK(zzzsExamine);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param zzzsExamine
     */
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_examine:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ZzzsExamine zzzsExamine) {
        return super.exportXls(request, zzzsExamine, ZzzsExamine.class, "审批表");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("zzzs_examine:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ZzzsExamine.class);
    }

}
